package com.lyz.remote.impl;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.zip.GZIPOutputStream;

import org.apache.log4j.Logger;

import com.lyz.config.ConfigFactory;
import com.lyz.config.IConfig;
import com.lyz.core.impl.Context;
import com.lyz.log.filter.IFilter;
import com.lyz.remote.IMsgHandler;
import com.lyz.util.ClassUtil;
import com.lyz.util.PropertiesUtil;
import com.lyz.util.SleepUtil;
/**
 *   控制台打印日志
 * @author luyongzhao
 *
 */
public class ConsoleMsgHandler implements IMsgHandler {
	
	private static final Logger logger = Logger.getLogger(ConsoleMsgHandler.class);
	
//	private static final String RESP_SUCCESS = "200";
	
	/*标签，以辨别该socket传输的是哪种日志文件*/
	private String tag;
	
	private IFilter filter = null;
	
	private IConfig config = null;
	

	public IMsgHandler initHandler(String tag, Context context) {
		this.tag = tag;
		config = ConfigFactory.getConfig();
		filter = (IFilter)ClassUtil.newInstance(config.getFilter(tag));
		return this;
	}
	
	public boolean sendMsg(String msg) {
		
		if(msg == null || "".equals(msg.trim())){
			logger.debug("msg is empty...");
			return true;
		}
		/*过滤数据*/
		msg = filter.filter(msg);
		if(msg == null){
			return true;
		}
		boolean flag = false;
		
		logger.info(msg);
		
		return true;
		
	}

	@Override
	public boolean sendMsg(byte[] msg) {
		
		return true;
	}

	
	
	

}
